package com.lovely602.eureka.admin;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

public final class HealthCheck {

  @Component
  public static class Version extends AbstractHealthIndicator {

    @Override
    protected void check(Builder builder) {

      builder.withDetail("version", "1.0.0");
    }
  }

  @Slf4j
  public abstract static class AbstractHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
      try {
        Builder builder = Health.up();
        check(builder);
        return builder.build();
      } catch (Exception e) {
        log.error("", e);
        return Health.down(e).build();
      }
    }

    protected abstract void check(Builder builder) throws Exception;
  }
}
